/**
 * 页面基类
 * User: Mr.Co
 * Date: 13-5-30
 * Time: 上午11:46
 * Desc: 控制整个站点加载效果，以及访问权限问题
 */
GLOBAL.Namespace('PageBase',function(){
    var _this = this,
        _pagebase = GLOBAL.PageBase,
        _isMain = $('#mainContainer').size() > 0;

    /*
     * 通用数据请求处理地址
     */
    this.ServiceURL = '/service/main.ashx';

    /*
     * @单点登录用户ID
     */
    //this.SingleUserID = GLOBAL.cookie('AuthUser_LoginId');

    /*
     * @当前登录管理员信息
     */
    this.UserInfo = GLOBAL.Cookie('CustomerMember') ? eval('(' + GLOBAL.Cookie('CustomerMember') + ')') : {};

    /*
     * @当前登陆管理员所负责项目信息
     */
    //this.CustomerProject = GLOBAL.cookie('CustomerProject') ? eval('(' + GLOBAL.cookie('CustomerProject') + ')') : {};

    //单点登录
    /*if (this.SingleUserID != '' && !this.UserInfo.data) {
        var _loadUserInfo = function (dataHandle) {
            var param = '{fucid:"login_select",data:"' + _this.SingleUserID + '"};';
            dataHandle.getData({
                url: _this.ServiceURL,
                handler: 'data',
                parame: param,
                dataType: 'text',
                async: false,
                success: function (result) {
                    var _data = result;
                    result = eval('(' + result + ')').data;
                    if (result && result.length > 0 && result[0].UserId && result[0].UserId != '') {
                        GLOBAL.cookie('CustomerMember', _data, { expires: 7, path: '/' });
                        this.UserInfo = result[0];
                    } else {
                        var _domain = location.host.indexOf('wanda.cn') > -1 ? 'wanda.cn' : 'wanda-dev.cn';
                        GLOBAL.cookie('AuthUser_AuthMAC', '', { path: '/', domain: _domain, expires: -1 });
                        GLOBAL.cookie('AuthUser_AuthNum', '', { path: '/', domain: _domain, expires: -1 });
                        GLOBAL.cookie('AuthUser_AuthToken', '', { path: '/', domain: _domain, expires: -1 });
                        GLOBAL.cookie('AuthUser_LoginId', '', { path: '/', domain: _domain, expires: -1 });
                        location.href = '/html/403.html';
                        return;
                    }
                }
            });
        }
        if (GLOBAL.dataStore && GLOBAL.dataStore.dataHandle) {
            _loadUserInfo(GLOBAL.dataStore.dataHandle);
        } else {
            GLOBAL.load('/scripts/pagekage/datastore/dataHandle.js', '', function () {
                _loadUserInfo(GLOBAL.dataStore.dataHandle);
            });
        }
    } else {
        this.UserInfo = this.UserInfo.data[0];
    }*/

    //设置Main页面的iframe高度
    //if (!_isMain) {
    //    setTimeout(function () {
    //        if (window.parent.GLOBAL.pagebase.initFrameHeight)
    //            window.parent.GLOBAL.pagebase.initFrameHeight($(document.body).height());
    //    }, 200);
    //}

    //设置Main页面的iframe高度,当页面中使用了异步绑定数据列表时候可能用到此方法
    _this.SetParentFrameHeight = function (height) {
        if (window.parent.GLOBAL.pagebase.initFrameHeight) {
            window.parent.GLOBAL.pagebase.initFrameHeight(height);
        }
        return _this;
    }

    /*
     * @子类扩展方法
     */
    _this.Add = function (args) {
        if (!args) return;
        for (var o in args) {
            _this[o] = args[o];
        }
        return _this;
    };


    /*
     * @页面加载响应
     */
    _this.PageLoading = function () {
        var _docHeight = $(document.body).height(),
            _winHeight = $(window).height(),
            _loading = '<div id="pageLoading" style=" position: absolute; width:100%; height:' + _docHeight + 'px; background-color: white; z-index: 999; top:0px; left:0px; opacity:0.8;filter:alpha(opacity=80); "><img style="position:absolute; width:60px; height:60px; top:50%; margin-top:-30px; left:50%; margin-left:-30px; " src="" alt="loading..." /></div>';
        $(document.body).append(_loading);
        $(window).scrollTop(_docHeight / 2 - _winHeight / 2);
        return _this;
    };

    /*
     * @移除loading
     */
    _this.RemoveLoading = function () {
        $('#pageLoading').remove();
        return _this;
    };

    /*
     *@初始化iframe页面中的高度，如果高度低于窗口高度则设置为最高高度
     */
    _this.InitFramePageHeight = function () {
        if (_isMain) return;
        setTimeout(function () {
            var _$body = $(document.body),
            _bodyH = _$body.height(),
            _$window = $(window),
            _windowH = _$window.height();            
            _$body.height(_bodyH > _windowH ? _bodyH : _windowH);
        }, 100);
    };

    /*
     *@ 弹出窗口
     */
    _this.WindowOpen = function (url, name, iWidth, iHeight) {
        var url; //转向网页的地址;
        var name; //网页名称，可为空;
        var iWidth; //弹出窗口的宽度;
        var iHeight; //弹出窗口的高度;
        var iTop = (window.screen.availHeight - 30 - iHeight) / 2; //获得窗口的垂直位置;
        var iLeft = (window.screen.availWidth - 10 - iWidth) / 2; //获得窗口的水平位置;
        window.open(url, name, 'height=' + iHeight + ',,innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
    };    
});
